package com.blb.springboot.interceptor;
import com.blb.springboot.entity.Address;
import com.blb.springboot.entity.Good;
import com.blb.springboot.service.AddressService;
import com.blb.springboot.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author lvtian
 * @date 2023/1/5 20:15
 */

public class DropBoxInterceptor implements HandlerInterceptor {
    @Autowired
    private GoodService goodService;
    @Autowired
    private AddressService addressService;

    //前置
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        List<Good> goodsList = goodService.list();
        List<Address> addressList = addressService.list();
        request.setAttribute("goodsList",goodsList);
        request.setAttribute("addressList",addressList);
        return true;
    }
    //后置
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }
    //请求完成后
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
